<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>资源描述</title>
    <link href="${contextPath}/resource/css/a4yy/index.css" rel="stylesheet" type="text/css"/>
    <#include "/common/common.ftl">
    <style>
        .logo{
            box-sizing: border-box;
            background-repeat: no-repeat;
            background-position: top;
            background-size: 100%;
            position: absolute;
            left: 0;
            right: 0;
            top: 50px;
            bottom: 0;
        }
        .space{
            margin:0 5px 0 0;
            user-select: none;
            cursor: hand;
        }
        .part{
            display: inline-block;
            background-color: #FFFFFF50;
            padding:5px;
        }
        .part-line{
            background-color: #FFFFFF50;
            height:1px;
            margin-bottom:5px;
        }
    </style>
</head>
<body>
    <input id="urlBox" type="hidden" value="${param!}"/>
    <div class="tool-bar">
        <Button id="goIndex">返回主页</Button>
        <button id="nextBtn" style="display: none;">下一页</button>
        <button id="prevBtn" style="display: none;">上一页</button>
    </div>
    <div class="logo"></div>
    <div id="partContent" style="position: absolute;top:60px;left:0;right:0;" />
    <div class="content">
    </div>
</body>
<script>
    $(function(){
        $("#goIndex").click(function(){
            location.href=basePath+"/a4yy/to/index";
        });
        $(document).on("click","[part]",function(){
            open("http://aaxxy.com"+$(this).data("linked"),"_blank")
        });
        $("#nextBtn").click(function(){
            if($(this).data("linked")){
                request($(this).data("linked"));
            }
        });
        $("#prevBtn").click(function(){
            if($(this).data("linked"))
            request($(this).data("linked"));
        });
        $(document).on("click","div[class=content]>div",function(){
            var url=$(this).data("linked");
            location.href=basePath+"/a4yy/to/detail?param="+url;
        });
        var url=$("#urlBox").val();
        $("#urlBox").remove();
        request(url);
    })

    function request(url){
        $.ajax({
            url:basePath+"/a4yy/getDetail",
            data:{url:url},
            type:"get",
            dataType:'json',
            success:function(data){
                if(data.constructor===Array){
                    initList(data);
                    $("#nextBtn").show();
                    $("#prevBtn").show();
                    $("#prevBtn").data("linked",data[0]);
                    $("#nextBtn").data("linked",data[1]);
                    return;
                }
                var detail=data;
                var description=detail.description;
                var imgContent=$("div.logo");
                var imgUrl = detail.imageUrl;
                imgContent.css("background-image","url("+imgUrl+")");
                var playerList=detail.playerList;
                var content=$("#partContent");
                content.html('');
                $("<div style='margin-bottom:10px;background-color: #FFFFFFA0;font-size:18px;'></div>").appendTo(content).text(detail.name);
                $("<div style='margin-bottom:10px;background-color: #FFFFFFA0;'></div>").appendTo(content).text(description);
                if(playerList){
                    for(var i=0;i<playerList.length;i++){
                        var detail = playerList[i];
                        var partLine=detail.playerArea;
                        var t = $("<span class='part'></span>").appendTo(content);
                        t.text(partLine);
                        $("<div class='part-line'></div>").appendTo(content);
                        var detailList = detail.list;
                        for(var j=0;j<detailList.length;j++){
                            var s = $("<span class='part space' part></span>").appendTo(content);
                            s.text(detailList[j].name);
                            s.data("linked",detailList[j].url);
                        }
                        $("<div style='height:20px;'></div>").appendTo(content);
                    }
                }
            }
        });
    }

    function initList(list){
        var content = $("div[class=content]");
        content.html('');
        for(var i in list){
            if(typeof(list[i])==='string' || list[i]==null){
                continue;
            }
            var info = list[i];
            var div=$("<div></div>").appendTo(content);
            div.data("linked",info.detailUrl);
            $("<div class='img' style='background-image:url("+info.imageUrl+");'></div>").appendTo(div);
            var infoContent = $("<div class='info'></div>").appendTo(div);
            var ul = $("<ul></ul>").appendTo(infoContent);
            var li=$("<li></li>").appendTo(ul);
            li.text(info.name);
            li=$("<li></li>").appendTo(ul);
            li.text("无");
        }
    }
</script>
</html>